import requests,json
import pandas as pd
key='18ef7dd6aeefc21dade574262c00f213'
def geocode(key,address,city=None,batch='false',sig=None,output='json',callback=None):
    """"获取好的Api的地理编码信息"""
    url='https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
    'key':key,
    'address':address,
    'city':city,
    'batch':batch,
    'sig':sig,
    'output':output,
    'callback':callback
    }
    response=requests.get(url,params=params)
    results=response.json()['geocodes'][0]['location']
    # return
    return results
###################################################################################
def regeo(key,location,poitype=None,radius='1000',extensions='base',batch='false',roadlevel=None,sig=None,
          output='json',callback=None,homeorcorp='0'):
    # 通过经纬度来判断位置
    url='https://restapi.amap.com/v3/geocode/regeo?parameters'
    params={
        'key':key,
        'location':location,
        'poitype':poitype,
        'radius':radius,
        'extensions':extensions,
        'batch':batch,
        'sig':sig,
        'output':output,
        'callback':callback,
        'homeorcorp':homeorcorp
    }
    response=requests.get(url,params)
    results=response.json()
    return results
######################################################
def walking(key,origin,location,sig=None,output='json',callback=None):
    #步行路径规划
    url='https://restapi.amap.com/v3/direction/walking?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':location,
        'sig':sig,
        'output':output,
        'callback':callback,
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results

#################################################################################
def transit(origin, location, city, cityid=None, extensions='base', strategy=0, nightflag=0,
            date=None, time=None, sig=None, output='json', callback=None):
    # 公交路径规划
    url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
    params = {
        'key': key,
        'origin': origin,
        'destination': location,
        'city': city,
        'cityid': cityid,
        'extensions': extensions,
        'strategy': strategy,
        'nightflag': nightflag,
        'date': date,
        'time': time,
        'sig': sig,
        'output': output,
        'callback': callback

    }
    response = requests.get(url, params)
    results = response.json()
    # return
    return results
######################################################
def driving(key,origin,destination,extensions):
    #驾车路径规划
    url='https://restapi.amap.com/v3/direction/driving?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
        'extensions':extensions
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results
######################################################################
def bicycling(key,origin,destination):
    #骑车路径规划
    url='https://restapi.amap.com/v4/direction/bicycling?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results
##########################################################################
def truck(key,origin,location,size):
    #货车路径规划
    url='https://restapi.amap.com/v4/direction/truck?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':location,
        'size':size
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results
##############################################################################
def distance(origins, location, type=''):
    # 测量距离
    url = 'https://restapi.amap.com/v3/distance?parameters'
    key = '18ef7dd6aeefc21dade574262c00f213'
    params = {
        'key': key,
        'origins': origins,
        'destination': location,
        'type': type

    }
    response = requests.get(url, params)
    results = response.json()
    # return
    return results
############################################################################
def district(key,keywords=None,subdistrict='1',page='1',offset='20',extensions='base',filter='',callback=None,output='json'):
    #行政区域查询
    url='https://restapi.amap.com/v3/config/district?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'subdistrict':subdistrict,
        'extensions':extensions,
        'page':page,
        'offset':offset,
        'filter':filter,
        'callback':callback,
        'output':output
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results
###############################################################################333
def text(keywords, city='', extensions='', citylimit=''):
    # 关键词搜索
    url = 'https://restapi.amap.com/v3/place/text?parameters'
    key = '18ef7dd6aeefc21dade574262c00f213'
    params = {
        'key': key,
        'keywords': keywords,
        'city': city,
        'extensions': extensions,
        'citylimit': citylimit

    }
    response = requests.get(url, params)
    results = response.json()
    # return
    return results
#####################################################################################
def around(location, keywords=''):
    # 周边搜索
    url = 'https://restapi.amap.com/v3/place/around?parameters '
    key = '18ef7dd6aeefc21dade574262c00f213'
    params = {
        'key': key,
        'keywords': keywords,
        'location': location

    }
    response = requests.get(url, params)
    results = response.json()
    # return
    return results
#################################################################################
def poly(key,polygon,keywords=None,types=None,offset='20',page='1',extensions='base',sig=None,output='json',callback=None):
    #多边形搜索
    url='https://restapi.amap.com/v3/place/polygon?parameters '
    params={
        'key':key,
        'polygon':polygon,
        'keywords':keywords,
        'types':types,
        'offset':offset,
        'page':page,
        'extensions':extensions,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    results=response.json()
    # return
    return results
##################################################################################
def detail(id):
    # id查询搜索
    url = 'https://restapi.amap.com/v3/place/polygon?parameters '
    key = '18ef7dd6aeefc21dade574262c00f213'
    params = {
        'key': key,
        'id': id

    }
    response = requests.get(url, params)
    results = response.json()
    # return
    return results
################################################################################
def ip(key, id):
    # ip定位
    url = 'https://restapi.amap.com/v3/ip?parameters'
    key = '18ef7dd6aeefc21dade574262c00f213'
    params = {
        'key': key,
        'id': id

    }
    response = requests.get(url, params)
    results = response.json()
    # return
    return results
#####################################################################################
def amap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic='0',sig=None):
    #获取静态地图信息
    url='https://restapi.amap.com/v3/staticmap?parameters'
    params={
    'key':key,
    'location':location,
    'zoom':zoom,
    'scale':scale,
    'markers':markers,
    'labels':labels,
    'paths':paths,
    'traffic':traffic,
    'sig':sig
    }
    r=requests.get(url,params)
    data=r.url
    return data
##########################################################################################
def convert(key,locations,coordays='',sig='',output=''):
    # 坐标转换
    url='https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'
    params={
        'key':key,
        "locations":locations,
        'coordays':coordays,
        'sig':sig,
        'output':output
    }
    response=requests.get(url,params)
    r=response.json()
    return r
#######################################################################################
def weather(key,city,extensions='base',output=''):
    # 天气查询
    url='https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    params={
        'key':key,
       'city':city,
        'extensions':extensions,
        'output':output
    }
    response=requests.get(url,params)
    r=response.json()
    return r
#######################################################################################
def input(key,keywords,type=None,location=None,city=None,
          citylimit='false',datatype=None,sig=None,output='json',callback=None):
    # 输入提示
    url='https://restapi.amap.com/v3/assistant/inputtips?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'type':type,
        'location':location,
        'city':city,
        'citylimit':citylimit,
        'datatype':datatype,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    response=requests.get(url,params)
    r=response.json()
    return r
